<template>
  <div class="app-container">
    <div class="backgroundClass">
      <div class="titleBox">
        <span class="title_fontSize">个人信息</span>
        <p v-if="userstate&&userstate.audit_state=='审核不通过'" style="color:#f00;margin-left:24px;">温馨提醒：{{userstate.audit_remark}} ，请修改!</p>
        
      </div>
      <div class="backgroundClass">
        
        <el-form
          label-position="left"
          :label-width="!studentinforsite?'80px':'150px'"
          :model="formLabelAlignA"
          v-loading="loading"
          style="display:flex;width:100%;"
          class="from"
        >
          <div style="width:25%;" v-if="!studentinforsite">
            <el-form-item label="身份证号">
              <el-input disabled v-model="adminUserId"></el-input>
            </el-form-item>
            <el-form-item label="用户姓名">
              <el-input disabled v-model="nickname"></el-input>
            </el-form-item>
            <el-form-item label="原密码">
              <el-input
                type="password"
                v-model="formLabelAlignA.oldpassword"
                placeholder="请输入原密码"
              ></el-input>
            </el-form-item>
            <el-form-item label="新密码">
              <el-input
                type="password"
                v-model="formLabelAlignA.newpassword"
                placeholder="请输入新密码"
              ></el-input>
            </el-form-item>
            <el-form-item label="专业">
              <el-input
                disabled
                v-model="formLabelAlignA.subjectTitle"
              ></el-input>
            </el-form-item>
            <el-form-item label="部门" v-if="formLabelAlignA.name">
              <el-input disabled v-model="formLabelAlignA.name"></el-input>
            </el-form-item>
            <el-form-item label="公司名称">
              <el-input disabled v-model="formLabelAlignA.company"></el-input>
            </el-form-item>
            <el-form-item label="用户性别">
              <el-input disabled v-model="formLabelAlignA.gender"></el-input>
            </el-form-item>
            <el-form-item label="手机号" v-if="formLabelAlignA.phone">
              <el-input disabled v-model="formLabelAlignA.phone"></el-input>
            </el-form-item>
          </div>
          <div style="width:100%;" v-else>
            <!-- <el-form-item label="用户性别">
              <el-input disabled v-model="formLabelAlignA.gender"></el-input>
            </el-form-item> -->
            <siteInfor :userInfo='valueObj' ref="siteInfor"></siteInfor>
          </div>
        </el-form>
        <el-button @click="commit" v-if="!studentinforsite">提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { userinfo, passwordEdit ,applyList,downloadAll} from "@/api/admin.js";
import { mapGetters } from "vuex";
import { getsubject_id, getsubjectTitle,getPhone,getGender,getuserstate } from "@/utils/auth";
import siteInfor from '@/components/siteInfor'
export default {
  data() {
    return {
      formLabelAlignA: {
        oldpassword: "",
        newpassword: "",
        subjectTitle: "",
        name: "",
        gender: "",
        phone: "",
        company:'',
        gz:'',
      },
      valueObj:{},
      loading: false,
      studentinforsite:false,
      userstate:getuserstate()&&getuserstate()!='undefined'?JSON.parse(getuserstate()):null,
      baseUrl:process.env.NODE_ENV === 'development' ? process.env.VUE_APP_BASE_API :window.location.href.slice(0, window.location.href.indexOf('/user')),
      fileList:[],
    };
  },
  computed: {
    ...mapGetters(["userinfor", "nickname", "adminUserId",'initObj']),
  },
  watch:{
    
  },
  components:{siteInfor},
  methods: {
    //修改密码 提交
    commit() {
      if (!this.formLabelAlignA.oldpassword) {
        return this.$message.error("原密码不能为空");
      }
      if (!this.formLabelAlignA.newpassword) {
        return this.$message.error("新密码不能为空");
      }
      this.loading = true;
      passwordEdit({
        password_old: this.formLabelAlignA.oldpassword,
        password_new: this.formLabelAlignA.newpassword,
      }).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.$message.success("密码修改成功");
          // this.$router.push("/login");
        }
      });
    },
    //附件下载
    download(){
      if(!this.userstate.attachment||this.userstate.attachment=='[]'){
        return this.$message.error('暂无附件')
      }
      let imglist = JSON.parse(this.userstate.attachment)
      imglist.map((item)=>{
        setTimeout(()=>{
          downloadAll(item,'登记表')
        },1000)
      })
    },
   
  },
  created() {
    this.formLabelAlignA.subjectTitle = getsubjectTitle();
    this.userinfor.map(item=>{
        if(item.subject_id==getsubject_id()){
          this.valueObj=item
          this.formLabelAlignA.phone=item.phone
          this.formLabelAlignA.company=item.company
          this.formLabelAlignA.gz=item.gz
          this.formLabelAlignA.gender=getGender()
        }
    })
    this.valueObj.nickname=this.nickname
    this.valueObj.username=this.adminUserId
    this.valueObj.phone=getPhone()
    this.valueObj.subjectTitle=getsubjectTitle()
    let obj = JSON.parse(this.initObj.setting)
    this.studentinforsite=obj.studentinforsite&&obj.studentinforsite=='开启'?true:false
    
  },
  mounted() {
    if(this.studentinforsite){
      this.$refs.siteInfor.gzChange(this.formLabelAlignA.gz)
    }
  },
};
</script>

<style lang="scss" scoped>
@import "~@/styles/utis.scss";
.titleBox {
  display: flex;
  min-width: 500px;
  border-bottom: 1px solid #eeeeee;
  padding-bottom: 24px;
  display: flex;
  align-items: center;
  p{
    margin-bottom: 0;
  }
  .title_fontSize {
    // line-height: 32px;
    font-size: 18px;
  }
}
::v-deep{
  .is-disabled{
    input{
      color:#333 !important;
    }
  }
  
}
// .from{
//   height: calc(100vh - 48px - 48px - 48px - 24px - 50px - 48px);
//   overflow: auto;
// }

</style>